//package com.basin.common.glc.func;
//
//import cn.hutool.core.lang.UUID;
//import com.basin.common.glc.constance.BasinLogConst;
//import com.basin.common.glc.context.BasinLogContext;
//import com.basin.common.glc.pojo.BasinLogVO;
//import com.basin.common.glc.wrapper.CachedBodyHttpServletRequest;
//import org.springframework.http.HttpRequest;
//import org.springframework.http.client.ClientHttpRequestExecution;
//import org.springframework.http.client.ClientHttpRequestInterceptor;
//import org.springframework.http.client.ClientHttpResponse;
//import org.springframework.stereotype.Component;
//
//import java.io.BufferedReader;
//import java.io.IOException;
//import java.io.InputStreamReader;
//import java.nio.charset.StandardCharsets;
//import java.util.stream.Collectors;
//
/// **
// * @author: Sam ZHONG | sammy1997@aliyun.com
// * @date: 2025/6/21 18:30
// * @description:
// */
//@Component
//public class BasinClientHttpRequestInterceptor implements ClientHttpRequestInterceptor {
//
//    @Override
//    public ClientHttpResponse intercept(HttpRequest request, byte[] body,
//                                        ClientHttpRequestExecution execution) throws IOException {
//        BasinLogVO parentLog = BasinLogContext.get();
//        long startTime = System.currentTimeMillis();
//        BasinLogVO basinLogVO = new BasinLogVO();
//        basinLogVO.setTraceId(parentLog.getTraceId());
//        basinLogVO.setLogId(UUID.fastUUID().toString(true));
//        basinLogVO.setStartTime(startTime);
//        basinLogVO.setRequestUri(request.getURI().toString());
//
//
//        ClientHttpResponse response = execution.execute(request, body);
//        // 获取响应结果
//        String resStr = new BufferedReader(new InputStreamReader(response.getBody(), StandardCharsets.UTF_8)).lines()
//                .collect(Collectors.joining());
//
//        String bStr = new String(body, StandardCharsets.UTF_8);
//
//        basinLogVO.setParams(bStr);
//        basinLogVO.setResult(resStr);
//
//        long end = System.currentTimeMillis();
//        long costTime = end - startTime;
//        basinLogVO.setCostTime(costTime);
//        basinLogVO.setEndTime(end);
//
//        parentLog.getTraces().add(basinLogVO);
//
//        return response;
//    }
//}